<?php
ob_start();
if(empty($_SESSION)) session_start();

$svn = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;

switch($svn){
	
	case "37.218.250.34";
	
		// header('Content-Type: text/html; charset=iso-8859-1');
		define("SERVERNAME", "mariadb-lyad-db.jelastic.dogado.eu");
		define("USER", "root");
		define("PWD", "tO0opcHnyh");
		define("DBNAME", "geoplugins");

		
		
	break;
	
	
	default:
		
		define("SERVERNAME", "localhost");
		define("USER", "root");
		define("PWD", "");
		define("DBNAME", "geoplugins");



	break;
}

define("MAILID", "lyad.fr.test@gmail.com");
define("PWMAIL", "lyad.fr.test123123");
define("NAMEAPP", "Lyad Affilitation ");


$g_link = false;


function connection($pdo=false){
	global $g_link;
	// if( $g_link ) return $g_link;	

	if(!$pdo){
		if($g_link) @mysql_close($g_link);
		
		$g_link = mysql_connect( SERVERNAME, USER, PWD) or die('Could not connect to server.' );
		try {
			mysql_select_db(DBNAME, $g_link);
		} catch (PDOException $e) {
			die("Failed to get DB handle: " . $e->getMessage());
		}
		
	}else{
		try {
			$g_link = new PDO("mysql:host=".SERVERNAME.";dbname=".DBNAME, USER, PWD);
		} catch (PDOException $e) {
			die("Failed to get DB handle: " . $e->getMessage());
		}
		
	}
	
	return $g_link;
}

function writelog($file,$content){
	
	@file_put_contents($file, $content."\n", FILE_APPEND | LOCK_EX);
}


function cleanUpDB()
{
	global $g_link;
	if( $g_link != false )
		mysql_close($g_link);
	$g_link = false;
}
require dirname(__FILE__).'/functions/Assets.php';
//File common
require(dirname(__FILE__). '/functions/common.php');
$assets = new Assets();

require dirname(__FILE__).'/functions/mailer/PHPMailerAutoload.php';
function mailer($to=null,$subject='',$body='',$altBody = 'This is the body in plain text for non-HTML mail clients',$fullName = ''){
	$mail = new PHPMailer;

	$mail->isSMTP();                                      // Set mailer to use SMTP
	// $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup server
	$mail->Mailer = "smtp";
	$mail->Host = "smtp.gmail.com";
	$mail->Port = 587;
	$mail->SMTPAuth = true;                               // Enable SMTP authentication
	$mail->Username = MAILID;                            // SMTP username
	$mail->Password = PWMAIL;                           // SMTP password
	$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

	$mail->From = MAILID;
	$mail->FromName = PWMAIL;
	
	$mail->addAddress($to, $fullName );  // Add a recipient
	// $mail->addAddress('ellen@example.com');               // Name is optional
	// $mail->addReplyTo('info@example.com', 'Information');
	// $mail->addCC('cc@example.com');
	// $mail->addBCC('bcc@example.com');

	$mail->WordWrap = 5000;                                 // Set word wrap to 50 characters
	// $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
	// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
	$mail->isHTML(true);                                  // Set email format to HTML

	$mail->Subject = $subject;
	$mail->Body    = $body;
	$mail->AltBody = $altBody;

	// if(!$mail->send()) {
	   // echo 'Message could not be sent.';
	   // echo 'Mailer Error: ' . $mail->ErrorInfo;
	   // exit;
	// }

	// echo 'Message has been sent';
	return $mail->send();
}

?>
